window.onload = function () {
	var x = document.getElementById('navTree');
    var listItems = x.getElementsByTagName("LI");
	
    for (var i = 0; i < listItems.length; i++){
		var hasSubMenu = false; // assume LI has no sub menu
		var listItemsChildren = listItems[i].childNodes; // get all LI children
		// loop through children to see if the node is an element and the tag is a "UL"
		for (var count = 0; count < listItemsChildren.length; count++){ 
			if(listItemsChildren[count].nodeType == 1 && listItemsChildren[count].tagName == "UL"){
				// is a UL set hasSubMenu as true
				hasSubMenu = true;
			}
		}

		if (hasSubMenu == true){
			listItems[i].className+=' open';
			var firstChild = listItems[i].firstChild; // text node
			while (firstChild.nodeType != 1) {
				firstChild = firstChild.nextSibling;
			}
			firstChild.className+=' open';
			if(window.attachEvent){ // does the browser support this object method?
				listItems[i].attachEvent('onclick',clickNav) // ie
			} else if (window.addEventListener){ // does the browser support this object method?
				listItems[i].addEventListener('click',clickNav,false); // mozilla and most other browsers
			}
		}
	} 
	
	//onloadlistmenu();

}


///////////////////////////////////////////////////////
function onloadlistmenu () {

	//phan 1
	var x1 = document.getElementById('navTree1');
    var listItems = x1.getElementsByTagName("LI");
    for (var i = 0; i < listItems.length; i++){
		var hasSubMenu = false; // assume LI has no sub menu
		var listItemsChildren = listItems[i].childNodes; // get all LI children
		// loop through children to see if the node is an element and the tag is a "UL"
		for (var count = 0; count < listItemsChildren.length; count++){ 
			if(listItemsChildren[count].nodeType == 1 && listItemsChildren[count].tagName == "UL"){
				// is a UL set hasSubMenu as true
				hasSubMenu = true;
			}
		}

		if (hasSubMenu == true){
			listItems[i].className+=' closed';
			var firstChild = listItems[i].firstChild; // text node
			while (firstChild.nodeType != 1) {
				firstChild = firstChild.nextSibling;
			}
			firstChild.className+=' closed';
			if(window.attachEvent){ // does the browser support this object method?
				listItems[i].attachEvent('onclick',clickNav) // ie
			} else if (window.addEventListener){ // does the browser support this object method?
				listItems[i].addEventListener('click',clickNav,false); // mozilla and most other browsers
			}
		}
	}
	
}
///////////////////////////////////////////////////////

////////////
function clickNav(e)
{
	// cancel event bubbling
	if (!e) var e = window.event;
	e.cancelBubble = true;
	if (e.stopPropagation) e.stopPropagation();
	
	if (!e) var e = window.event;
	if (e.target) var tg = e.target;
	else if (e.srcElement) var tg = e.srcElement;
	
	while (tg.nodeName != 'LI'){ // Safari GRRRRRRRRRR
		tg = tg.parentNode;
	}
	
	var firstChild = tg.firstChild; // text node
	
	while (firstChild.nodeType != 1) {
		firstChild = firstChild.nextSibling;
	}
	// if elements class value contains and instance of open
	if (firstChild.className.search(/open/) >= 0){
	 	tg.className = tg.className.replace('open', 'closed');
		firstChild.className = firstChild.className.replace('open', 'closed');
	} else {
	 	tg.className = tg.className.replace('closed', 'open');
		firstChild.className = firstChild.className.replace('closed', 'open');
	}
}// JavaScript Document

function addCkeditor(name){
	CKEDITOR.replace(name, {
                customConfig: 'ckeditor/config.js',
                filebrowserBrowseUrl: 'ckfinder/ckfinder.html',
                filebrowserImageBrowseUrl: 'ckfinder/ckfinder.html',
                filebrowserFlashBrowseUrl: 'ckfinder/ckfinder.html?type=Flash',
                filebrowserUploadUrl: 'ckfinder/core/connector/php/connector.php?command=QuickUpload&type=Files',
                filebrowserImageUploadUrl: 'ckfinder/core/connector/php/connector.php?command=QuickUpload&type=Images',
                filebrowserFlashUploadUrl: 'ckfinder/core/connector/php/connector.php?command=QuickUpload&type=Flash'

            });
}